//
//  EWSectionHeaderView.m
//  haveSomethingToEat
//
//  Created by 陈 宁权 on 17/6/9.
//  Copyright © 2017年 陈 宁权. All rights reserved.
//

#import "EWSectionHeaderView.h"

@interface EWSectionHeaderView()

@property (nonatomic,strong) UILabel *label;

@end

@implementation EWSectionHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"EWSectionHeaderView";
    // 1.缓存中取
    EWSectionHeaderView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
        cell = [[EWSectionHeaderView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupChildViews];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setupChildViews
{
    _label = [[UILabel alloc] init];
    _label.text = _title;
    _label.textAlignment = NSTextAlignmentCenter;
    _label.textColor = [UIColor blackColor];
    _label.font = [UIFont systemFontOfSize:13];
    [self addSubview:_label];
    
    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.bottom.equalTo(self);
        make.height.offset(20);
        make.width.equalTo(self);
    }];
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    _label.text = _title;
}


@end
